package com.sky.mapper.user;

import com.sky.pojo.ShoppingCart;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ShoppingCartMapper {

    @Insert("insert into shopping_cart (name, user_id, dish_id, setmeal_id, dish_flavor, number, amount, image, create_time) " +
            " values (#{name},#{userId},#{dishId},#{setmealId},#{dishFlavor},#{number},#{amount},#{image},#{createTime})")
    void insert(ShoppingCart shoppingCart);

    @Select("select * from shopping_cart sc where user_id = #{userId} and (dish_id = #{dishId} or setmeal_id = #{setMealId})")
    ShoppingCart getByDishIdOrSetMealId(Long dishId,Long setMealId,Long userId);

    @Update("update shopping_cart set number = #{num} where id = #{id}")
    int updateNumById(Integer num,Long id);


    @Select("select * from shopping_cart where user_id = #{userId}")
    List<ShoppingCart> getByUserId(Long userId);

    Integer getMakeTime(Long userId);

    @Delete("delete from shopping_cart where user_id = #{userId}")
    void deleteByUserId(Long userId);
}
